
import { data } from "jquery";
import { myRequest } from "../../api/myRequest";
import { actionsMap } from "../../api/url";

const $RC = "Documents";
const $RC_actions = actionsMap[$RC];
export default {
  add(record) {
    return myRequest($RC, [{ action: $RC_actions.ADD, data: [record] }]);
  },

  /**
   * 删除信息
   * @param id
   * @returns {Promise<*>}
   */
  delete(filter) {
    return myRequest($RC, [{ action: $RC_actions.INSTANCE_DELETE, ...filter }]);
  },

  /**
   * 按Id删除信息
   * @param ids
   * @returns {Promise<*>}
   */
  deleteById(id) {
    return myRequest($RC, [{ action: $RC_actions.INSTANCE_DELETE_BY_ID, id: id }]);
  },

  /**
   * 批量删除信息
   * @param ids
   * @returns {Promise<*>}
   */
  batchDelete(filter) {
    return myRequest($RC, [{ action: $RC_actions.BATCH_DELETE, ...filter }]);
  },

  /**
   * 批量删除信息
   * @param ids
   * @returns {Promise<*>}
   */
  deleteByIds(ids) {
    return myRequest($RC, [{ action: $RC_actions.BATCH_DELETE, ids: ids }]);
  },

  /**
   * 更新信息
   * @param record
   * @returns {Promise<*>}
   */
  update(record) {
    return myRequest($RC, [{ action: $RC_actions.UPDATE, data: [record] }]);
  },

  /**
   * 查询列表
   * @param recipient
   * @returns {Promise<*>}
   */
  query(filter) {
    let recipient = [{ action: $RC_actions.QUERY, ...filter }];
    return myRequest($RC, recipient);
  },

  /**
   * 简单查询不包括属性或大字段信息
   * @param filter
   * @returns {Promise<*>}
   */
  queryInfo(filter) {
    let recipient = [{ action: $RC_actions.QUERY_INFO, ...filter }];
    return myRequest($RC, recipient);
  },

  /**
   * 分页查询列表
   * @param recipient
   * @returns {Promise<*>}
   */
  queryByPage(pageNumber, pageSize, filter, orderBy = "") {
    let recipient = [
      {
        action: $RC_actions.QUERY_BY_PAGE,
        pageNumber: pageNumber,
        pageSize: pageSize,
        ...filter,
        orderBy,
      },
    ];
    return myRequest($RC, recipient);
  },
  /**
   * 分页查询列表
   * @param recipient
   * @returns {Promise<*>}
   */
  queryInfoByPage(pageNumber, pageSize, filter) {
    let recipient = [
      {
        action: $RC_actions.QUERY_BY_PAGE,
        pageNumber: pageNumber,
        pageSize: pageSize,
        ...filter,
      },
    ];
    return myRequest($RC, recipient);
  },
};
